<?php

namespace App\Validators\Buz;

use Illuminate\Contracts\Validation\Factory;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use \Prettus\Validator\Contracts\ValidatorInterface;
use \Prettus\Validator\LaravelValidator;

class RemitBankValidator extends LaravelValidator
{


    protected $attributes = [
        'classify'   => '账户性质',
        'username'   => '开户名',
        'account'    => '开户账号',
        'category'   => '开户银行',
        'city_id'    => '开户行所在省市',
        'branch'     => '开户分支行',
        'number'     => '联行号',
        'is_default' => '是否默认'
    ];

    public function __construct(\Illuminate\Contracts\Validation\Factory $validator)
    {
        parent::__construct($validator);
        $this->rules = [
            'create' => [
                'classify' => 'required|in:0,1',
                'username' => 'required|max:150',
                'category' => 'required|max:20',
                'account'  => 'required|max:30|unique:plat_user_banks,account|bank_no',
                'city_id'  => 'required|exists:province_cities,id',
                'branch'   => 'required|max:255',
                'number'   => 'required_if:classify,1|max:255',
//                'is_default' => 'required|in:0,1'
            ],
            'update' => [
                'classify' => 'required|in:0,1',
                'username' => 'required|max:150',
                'category' => 'required|max:20',
                'account'  => [
                    'required',
                    'max:30',
                    Rule::unique('plat_user_banks')->ignore(Auth::user()->id, 'uid'),
                    'bank_no'
                ],
                'city_id'  => 'required|exists:province_cities,id',
                'branch'   => 'required|max:255',
                'number'   => 'required_if:classify,1|max:255',
//                'is_default' => 'required|in:0,1'
            ]
        ];
    }
}
